{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "CTC.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/harvardnlp/pytorch-struct/blob/master/notebooks/CTC_with_padding.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1A6gJZcOVq-h",
        "colab_type": "code",
        "outputId": "0467398c-3ac6-437a-8a42-cff49d155d2f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        }
      },
      "source": [
        "!pip install -qU git+https://github.com/harvardnlp/pytorch-struct\n",
        "!pip install -qU git+https://github.com/harvardnlp/genbmm\n",
        "!pip install -q matplotlib"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "  Building wheel for torch-struct (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for genbmm (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "r070BEdwVzHs",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import torch\n",
        "import torch_struct\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zxRC_exrbTR4",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Character Vocab, P is a padding token\n",
        "vocab = [\"a\", \"b\", \"c\", \"d\", \"e\", \"_\", \"P\"]\n",
        "v_dict = { a:i for i, a in enumerate(vocab)}\n",
        "L = len(vocab)\n",
        "\n",
        "# Char sequence\n",
        "letters = [[\"a\", \"_\", \"b\", \"_\", \"c\", \"_\", \"d\", \"_\", \"e\"], \n",
        "           [\"a\", \"_\", \"b\", \"_\", \"c\", \"P\", \"P\", \"P\", \"P\"]]\n",
        "#letters = [[\"a\", \"_\", \"b\", \"_\", \"c\"]]\n",
        "\n",
        "t = len(letters[0])\n",
        "\n",
        "# Padding\n",
        "\n",
        "# Frame sequence\n",
        "frames = [[\"a\", \"a\", \"a\", \"_\", \"b\", \"b\", \"c\", \"c\", \"c\", \"c\", \"_\", \"_\", \"d\", \"e\"], \n",
        "          [\"a\", \"a\", \"a\", \"a\", \"a\", \"_\", \"b\", \"b\", \"c\", \"c\", \"c\", \"c\", \"P\", \"P\"]] \n",
        "#frames = [[\"a\", \"a\", \"a\", \"a\", \"a\", \"_\", \"b\", \"b\", \"c\", \"c\", \"c\", \"c\"]] \n",
        "\n",
        "# Constants\n",
        "T, B = len(frames[0]), len(frames)\n",
        "D1, MATCH, D2 = 0, 1, 2\n",
        "\n",
        "batch_lengths = [(t, T), (t-4, T-2)]\n",
        "#batch_lengths = [(t, T)]\n",
        "\n",
        "def show(m, ex):\n",
        "    plt.yticks(torch.arange(len(letters[ex])), letters[ex])\n",
        "    plt.xticks(torch.arange(T), [str(frames[ex][x.item()]) for x in torch.arange(T)])\n",
        "    plt.imshow(m[ex].cpu().detach())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rDtLyNKPa1N0",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Gold alignment. \n",
        "gold = torch.zeros(B, t).long()\n",
        "for b in range(B):\n",
        "    for i, l in enumerate(letters[0]):\n",
        "        gold[b, i] = v_dict[l]\n",
        "gold = gold[:, None, :].expand(B, T, t)\n",
        "\n",
        "# Inputs (boost true frames a bit)\n",
        "logits = torch.zeros(B, T, L)\n",
        "for b in range(B):\n",
        "    for i in range(T):\n",
        "        logits[b, i, v_dict[frames[b][i]]] += 1 "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "il4pW6M9YOKP",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Construct the alignment problem from CTC\n",
        "\n",
        "# Log-Potentials\n",
        "log_potentials = torch.zeros(B, T, t, 3).fill_(-1e5)\n",
        "\n",
        "# Match gold to logits. \n",
        "match = torch.gather(logits, 2, gold)\n",
        "\n",
        "# CTC Rules:\n",
        "for b, (lb, la)  in zip(range(B), batch_lengths):\n",
        "    # la and lb are the sizes of the two (without padding)\n",
        "\n",
        "    # Never allowed to fully skip regular characters (little t)\n",
        "    log_potentials[b, :la, :lb:2,  D2] = -1e5\n",
        "\n",
        "    # Free to skip _ characters (little t)\n",
        "    log_potentials[b, :la, 1:lb:2, D2] = 0\n",
        "\n",
        "    # First match with character is the logit. \n",
        "    log_potentials[b, :la, :lb, MATCH] = match[b, :la, :lb]\n",
        "\n",
        "    # Additional match with character is the logit.\n",
        "    log_potentials[b, :la, :lb, D1] = match[b, :la, :lb]\n",
        "\n",
        "    # Match padding in an L shape\n",
        "    log_potentials[b, la:, lb-1, D1] = 0\n",
        "    log_potentials[b, -1, lb:, D2] = 0\n",
        "\n",
        "\n",
        "log_potentials = log_potentials.transpose(1, 2).cuda()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Hz5I8cnLfpHE",
        "colab_type": "code",
        "outputId": "cd673207-eb68-4964-be96-3886800ade75",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "# Show input scores\n",
        "show(match.transpose(1,2).exp(), 1)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJ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/7DC\n3c3/+Pn/t/h1I8m/JPnb6fOP+9TH16vqtSQ/S3IlyWfMP1Xz1+3X3f3TxdffS/L5EzL/i0le7u63\nk6S7313RXPOXc6GqbiXZSfLfSa5Pn7/xR6/0B6qqLyT5UpLnuvtuVf1bkvPmn475R2T/taWrvtZ0\n3fM5Hve6++pJmn+cR9SfTPLeIhLPJPmc+adq/lH4dFU9t/j6K0l+ckLm/yjJl6vq8SSpqksrmmv+\nKXWcof5hdn9YczvJN7P712/zT8/8o/DLJF9b/Dt8Ksm3TsL87n4zyTeS/Hhx6ukfVzHX/NPLJxMB\nhju2c9ScXou/sr56wEvPd/c7R70PnHSOqAGGO+7L8wA4hFADDCfUAMMJNcBwQg0wnFADDPf/KfFi\nycGaaRoAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "psn-rlomc3CY",
        "colab_type": "code",
        "outputId": "c3c01c84-dd3f-4d87-f7a4-3a1292080b13",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "show(log_potentials[:, :, :, 1].exp(), 1)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAKIUlEQVR4nO3dz6vld33H8de7cwMZk0YySaCb2Cwi\nTTGQu7igsS7ECCV/gBsXpnRxSSO4KmTTrWA2BTcRLqQg6iop2J0FI5XRIu0NztgMg13VupGaH9A2\nc0nC8O7iHurteJp7xpxz73vufTwgzBnOyZt3ksmT73zu9863ujsAzPV7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laDn/7bf7ZmX8Sfp7ky4t/hvuTfONOmN/d15J8NckPF0dPf72OueafXb4z\nEWC4Uzuj5uxa/Jb11SVvPdXdb570PnCnc0UNMNxp354HwDGEGmA4oQYYTqgBhhNqgOGEGmC4/wEv\nD3ULKXWGYgAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xqDiA1mqfu6Q",
        "colab_type": "code",
        "outputId": "e2c16154-1003-40c4-b3b0-2be9b79d16ee",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "# Find best alignment\n",
        "dist = torch_struct.AlignmentCRF(log_potentials)\n",
        "show(dist.argmax, 0)\n"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAJvUlEQVR4nO3dQailZR3H8d+/JmgEkxyTDLIhEBMX\nBc4iK0GcNi0Cg6KwsGhxF4WubCG6cBO0amnkIghzIRmKLYpiosRAmtEcUwelTbQTp6CF0CKeFveo\n1/HcuceZ973nf+58PjB4r/fMn2fOzHw9vue571NjjADQ1/vWvQAAzk+oAZoTaoDmhBqgOaEGaE6o\nAZo7NMfQuqpGjs4xedtNz843ez9s+PKBmYwxatm/rzn2UdexGjk1+di3LP+lbI4NXz4wk91C7dIH\nQHNCDdCcUAM0J9QAzQk1QHNCDdCcUAM0J9QAza0U6qp6oqqeraqXqmpr7kUB8LZVv4X8u2OMf1XV\n4SQnq+pXY4yzcy4MgG2rhvruqvrK4uOPJ7kuyTtC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JxQAzQn1ADNCTVAc0IN0Nwq9/q4EK8n+cd7ePxVi58zhzlnm2+++ZfS/KW7nCea\nnez6Hd+zfMPLe1VVp8YYxzZttvnmm2/+fsx26QOgOaEGaK5LqB/a0Nnmm2+++bPPbnGNGoDddXlF\nDcAuhPoSVVVHq+rFTZ0PU6mqB6rqnnWv43yEGqC5tYa6qp6oqmer6qXF4bjm769DVfVIVZ2pqseq\n6rJNml9Vd1bVC1V1uqoennK2+QdbVd1XVa9W1dNJrp9h/req6i9V9XxV/bSq3n9RA8cYa/uR5MrF\nPw8neTHJEfP37bk/mu3zKj6/+PxnSe7ZoPk3Jnk1yVU7fy/M35/5m/wjyU1J/pbksiQfSvL3if9s\n3pDk10k+sPj8wSR3XszMdV/6uLuqTid5JsnHk1xn/r765xjjz4uPf5HkCxs0/7YkvxxjvJ4kY4x/\nTTjb/IPtliSPjzHeGGP8J8mTE88/nu3/GJysqucXn3/yYgbOda+PPVXVrUm+mOTmMcYbVfXHJB80\nf1+duzdz6r2ac8+HjirJz8cY9041cJ2vqK9I8u9F5D6V5LPm77trq+rmxcd3JHl6g+b/IcnXqupI\nklTVlRPONv9geyrJ7VV1uKouT/LlieefSPLVqro62X7uq2rXGy6tYp2h/m2232w6k+RH2b58YP7+\neiXJ9xe/hg8n+cmmzB9jvJTkh0n+tLj89OOpZpt/sI0xnkvyaJLTSX6T5OTE819Ocn+S31XVC0l+\nn+Sai5npOxMBmlvbNWrOb/G/rCeWfOn4GOPsfq8H3jT3n01/9t/NK2qA5ta9PQ+APQg1QHNCDdCc\nUAM0J9QAzQk1QHP/BwKWOQXFkW6QAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RdOaPe6rfU5k",
        "colab_type": "code",
        "outputId": "2db5d26f-7bff-4d48-c08a-cf701fd31451",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "show(dist.argmax, 1)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAJw0lEQVR4nO3dMYhl53nH4f8bprCMwFhSII2VLdZE\nwQtZyBRW4sJYbrZM4caFFVIMm5i4UbqkNbhKGYPAaWxXdsDu3MjErA2GzGDJkRicKo5byYZgdsmC\neFPMRTte3517x75n5p3Z5wGxI87Rq0874sfZb849p7o7AMz1B5e9AADOJtQAwwk1wHBCDTCcUAMM\nJ9QAw+3temC9UJ0bu576yJ8fLTebzfz2w2Le7e4/XHdg56HOjSSHO5/6gcNabjab+e2Hxfz8SQds\nfQAMJ9QAwwk1wHBCDTCcUAMMJ9QAwwk1wHBCDTDcVqGuqu9U1VFVvVNVB0svCoBHtv1k4t909y+r\n6pkk/1FV/9bd7y25MABObBvqL1XVX62+/liSjyf5INSrq+yTK+0Xd7k8ADZufVTVp5N8NsnL3f1n\nSX6S5EOnz+nu17t7v7v3s/aRIgD8rrbZo/5Ikl919/2qeinJJxdeEwCnbBPq7yXZq6rjJF9J8uNl\nlwTAaRv3qLv7/5LcuYC1ALCG+6gBhhNqgOGEGmA4oQYYTqgBhhNqgOF2/xbyoyz6qmpvwb5kvfB8\n32D4La6oAYYTaoDhhBpgOKEGGE6oAYYTaoDhhBpgOKEGGE6oAYYTaoDhhBpguJ0866OqDpIc7GIW\nAL+punf7lJ2qWvqxPVwmD2WCpRx19/66A7Y+AIYTaoDhhBpgOKEGGE6oAYbbeHteVT2f5I01h17p\n7vd2vyQATtsY6lWMb1/AWgBYw9YHwHBCDTCcUAMMt5NnffAUWfoj3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4+d396X9leS51a/PJHk7yfPmX5/5C/+/cyMnbxv9\ny9Xf/2uSf7gK85N8Isl/JXnh9Pdhh2s3/+z5v179upfku0n+dvr8y976+FJVvZXkx0k+luTj5l+r\n+Uv7RXf/aPX1N5J86orM/0ySb3X3u0nS3b/c0Vzzt/NMVb2Z5DDJ/yT52vT5SzzrYytV9ekkn03y\ncnffr6p/T/Ih86/H/Avy+L2lu77XdOn5XI4H3X37Ks2/zCvqjyT51SoSLyX5pPnXav5FeLGqXl59\n/fkkP7wi87+f5HNV9XySVNVzO5pr/jV1maH+Xk5+WHOc5Cs5+eO3+ddn/kX4WZIvrv4bPprkq1dh\nfne/k+TLSX6w2nr6513MNf/68slEgOEubY+a62v1R9Y31hx6pbvfu+j1wFXnihpguMu+PQ+ADYQa\nYDihBhhOqAGGE2qA4YQaYLj/B4z+V3jbsn5ZAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wdMZ89-ehpxq",
        "colab_type": "code",
        "outputId": "2d836e19-2e0f-405d-a79e-58bc548622f9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "# Find marginals (see uncertainty from randomness)\n",
        "show(dist.marginals, 0)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAALKklEQVR4nO3dX6jed30H8PfHJLMpRmfSBgT7Zxtd\nW9yfjubCTh1ivNlFwYHicFLGYGcwwaveiB24i4JXu9iF4rkYlOpF0WFxsEkl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HkseT\nXHbm34X83cnfyz+S3JjkH5JcmuTNSb6/8Ofm9Un+KsmB7Y8/k+SWc8k830sfH6+qB5N8O8kVSa6R\nv6t+2N3f2n78+STv3kP570vyxe5+Ikm6+8kFs+Vf2N6T5Mvd/Wx3P53kKwvnH8/WPwYnq+rU9se/\neC6Ba90zcYSqem+S9ye5qbufraq/S3KJ/F119rmZS5+rOTofZlRJ7ujuTywVeD6PqN+S5Kntkrsu\nyTvl77orq+qm7ccfSXLvHsr/epIPVdWRJKmqwwtmy7+wfTPJB6rqYFUdSnLzwvknknywqo4mW3/2\nVXXVuQSez6L+ara+2fRokk9na/lA/u56LMnHtn8Pb03y2b2S392PJLk9yTe2l5/+bKls+Re27n4g\nyV1JHkzyN0lOLpz/vSS3Jbmnqh5K8rUkbzuXTFcmAkzuvK1R89q2/8t6YsVLx7v79G7PAy8Z/bnp\nc/+VHFEDTO58n54HwA4UNcDkFDXA5BQ1wOQUNcDkFDXA5P4Xb7dm40sU2EcAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "b2rayj96fpnF",
        "colab_type": "code",
        "outputId": "51966a09-b8ba-441d-edcc-d6cb69df6e9f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 263
        }
      },
      "source": [
        "# No uncertainty for the padding.\n",
        "show(dist.marginals, 1)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD2CAYAAAD/C81vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAKm0lEQVR4nO3dT4jnd3kH8PeTjNGEQEw2pbTU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5C/+/82B23jb6wd2f/22SvzgO\n+Unen+Rfkty/989hg7PL3z//1d0ft5L8Q5I/m55/1Fsfn6qq55N8M8l7krxP/onKX9pL3f3M7ucv\nJvnQMcn/SJInu/tyknT3KxvKlb+eO6vquSQXkvwgyeem5y/xrI+1VNWHk3w0ySPdfaWq/jnJu+Sf\njPxDcvO1pZu+1nTpfI7G1e4+c5zyj3JFfU+SH+2WxMNJPiD/ROUfhgeq6pHdzx9P8o1jkv+1JB+r\nqlNJUlX3bShX/gl1lEX91ex8s+ZSks9k58tv+Scn/zB8N8knd/8d7k3y2eOQ390vJvl0kq/vbj39\n9SZy5Z9c7kwEGO7I9qg5uXa/ZH1qxaFHu/vlw54HjjsraoDhjvryPAAOoKgBhlPUAMMpaoDhFDXA\ncIoaYLj/A4hxk4z6BaJJAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sWLCBtu1hr5S",
        "colab_type": "code",
        "outputId": "bd0fc5ec-3da5-43cf-b42b-0494ea5983ea",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# Print the log sum exp of the data (for training)\n",
        "print(dist.partition)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "tensor([19.6766, 15.4172], device='cuda:0', grad_fn=<SqueezeBackward1>)\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}